<template>
  <div class="main">
    <el-container class="main-content">
      <el-aside :width="isCollapse ? '60px' : '210px'">
        <nav-menu :Collapse="isCollapse" />
      </el-aside>
      <el-container class="page">
        <el-header class="page-header">
          <nav-header @foldChange="foldChange" />
        </el-header>
        <el-main class="page-content">
          <div class="page-info">
            <router-view></router-view>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue"
import NavMenu from "@/components/nav-menu"
import NavHeader from "@/components/nav-header"
import { mainStore } from "@/stores/modules/main"
import useEchart from "@/base-ui/echart/hooks/useEchart"
import baseEchart from "@/base-ui/echart"

export default defineComponent({
  components: {
    NavMenu,
    NavHeader
  },
  setup() {
    const mainstore = mainStore()
    // 初始化菜单和按钮权限
    mainstore.getInit()
    // 获取所属菜单（菜单管理）
    mainstore.getOptionMenu()
    // 获取所属菜单（权限管理）
    mainstore.getOptionPerm()
    // 获取所有角色
    mainstore.getOptionRoles()

    // 是否折叠菜单栏
    const isCollapse = ref(false)
    const foldChange = (isFold: boolean) => {
      isCollapse.value = isFold
      const { updateSize } = useEchart(baseEchart.echartRef.value!)
      // 图表响应式
      window.addEventListener("resize", () => {
        updateSize()
      })
    }
    return {
      isCollapse,
      foldChange
    }
  }
})
</script>

<style scoped lang="less">
.main {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.main-content,
.page {
  height: 100%;
}

.page-content {
  height: calc(100% - 48px);
  .page-info {
    background-color: #fff;
    border-radius: 5px;
  }
}

.el-header {
  display: flex;
  color: #333;
  text-align: center;
  align-items: center;
}

.el-header {
  height: 48px !important;
}

.el-aside {
  overflow-x: hidden;
  overflow-y: auto;
  line-height: 200px;
  text-align: left;
  cursor: pointer;
  background-color: #001529;
  transition: width 0.3s linear;
  scrollbar-width: none; /* firefox */
  -ms-overflow-style: none; /* IE 10+ */

  &::-webkit-scrollbar {
    display: none;
  }
}

.el-main {
  color: #333;
  text-align: center;
  background-color: #f0f2f5;
}
</style>
